﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TestPlatform.Core;
using MongoDB.Driver;
using TestPlatform.Performer.MongoDB.Entities;

namespace TestPlatform.Performer.MongoDB
{
    public class MongoDBHelper : IDatabaseHelper
    {
        public static MongoDatabase GetDatabase()
        {
            return MongoServer.Create("mongodb://localhost/?safe=true").GetDatabase("MGR-DB");
        }

        public List<Guid> SeedDatabase(int count)
        {            
            List<Guid> ids = new List<Guid>();
            var collection = GetDatabase().GetCollection<User>("Users");           

            for (int i = 0; i < count; i++)
            {
                Guid id = Guid.NewGuid();
                collection.Insert(new User { Id = id, Login = id.ToString(), Name = id.ToString() });
                ids.Add(id);
            }

            return ids;
        }

        public void ClearDatabase()
        {
            GetDatabase().GetCollection<User>("Users").Drop();
        }
    }
}
